<?php

namespace App\Listeners\Train\TrainOrder;

use App\Events\Train\TrainOrder\TrainOrderTicketFailedEvent;
use App\Models\Train\TrainOrders\Repositories\Interfaces\TrainOrdersRepositoryInterface;
use App\Models\Train\TrainOrders\TrainOrder;

class TrainOrderTicketFailedListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param object $event
     *
     * @return void
     */
    public function handle(TrainOrderTicketFailedEvent $event)
    {
        /**
         * @var TrainOrder                     $order
         * @var TrainOrdersRepositoryInterface $trainOrderRepo
         */
        $order          = $event->order;
        $trainOrderRepo = app(TrainOrdersRepositoryInterface::class);

        $trainOrderRepo->ticketFailedAndRefund($order);
    }
}
